#pragma once 
#include "../Server.hpp"

class EchoServer
{
private:
    TcpServer _server;
private:
    void Connected(const PtrConnect&conn){
    //获取原生指针的地址
        DBG_LOG("CONNECTED: %p",conn.get());
    }
    void ClosedConnection(const PtrConnect&conn){
        //获取原生指针的地址
        DBG_LOG("CLOSED: %p",conn.get());
    }
    void Message(const PtrConnect&conn,Buffer*buff){
        conn->Send(buff->ReadPositoin(),buff->ReadAbleSize());
        buff->ReadMoveOffset(buff->ReadAbleSize());
        conn->Shutdown();
    }
public:
    EchoServer(uint16_t port)
        :_server(port)
        {
            _server.SetThreadCount(2);
            _server.EnableInactiveRelease(10);
            _server.SetClosedCallBack(std::bind(&EchoServer::ClosedConnection,this,std::placeholders::_1));
            _server.SetConnectedCallback(std::bind(&EchoServer::Connected,this,std::placeholders::_1));
            _server.SetMessageCallBack(std::bind(&EchoServer::Message,this,std::placeholders::_1,std::placeholders::_2));
        }
    void Start(){
        _server.Start();
    }
};